
import * as assert from 'assert';
import {createProxy} from '../../src/timeline/Proxy';

describe('Timeline: interpolation/extrapolation proxy', () => {

  it('should access top level properties', () => {

    const state = { one: 10, two: 20, newAttribute: 10 };
    const previousState = { one: 0, two: 30, oldAttribute: 10 };
    const proxy = createProxy( state, previousState, 0.5 );

    assert.equal( proxy.one, 5 );
    assert.equal( proxy.two, 25 );
    assert.equal( proxy.newAttribute, 10 );
    assert.equal( proxy.oldAttribute, 10 );
    assert.equal( proxy.undefinedAttribute, undefined );

  });

  it('should return a valid value when not a number', () => {

    const state = { one: 'current state, one', two: null };
    const previousState = { one: 'previous state, one', two: 'previous state, two' };
    const proxy = createProxy( state, previousState, 0.5 );

    assert.equal( proxy.one, 'current state, one' );
    assert.equal( proxy.two, null );

  });

  it('should access deeper properties', () => {

    const state = {
      one: { value: 10 },
      two: { value: 20 },
      newAttribute: { value: 100 },
    };

    const previousState = {
      one: { value: 0 },
      two: { value: 30 },
      oldAttribute: { value: 100 },
    };

    const proxy = createProxy( state, previousState, 0.5 );

    assert.equal( proxy.one.value, 5 );
    assert.equal( proxy.two.value, 25 );

    assert.equal( proxy.newAttribute.value, 100 );
    assert.equal( proxy.oldAttribute.value, 100 );
    assert.equal( proxy.undefinedAttribute, undefined );

  });

});
